package com.base.cn.platform.os.service.op.coupon;

import com.base.cn.platform.os.common.mybatis.BaseBiz;
import com.base.cn.platform.os.common.utils.ObjectUtils;
import com.base.cn.platform.os.dao.op.coupon.OpUserActivityCodeDao;
import com.base.cn.platform.os.entity.op.coupon.OpUserActivityCode;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * 用户参加活动赠送优惠券Biz
 *
 * @author s.li
 * @create 2018-10-03-11:30
 */
@Service
public class OpUserActivityCodeBiz extends BaseBiz<OpUserActivityCode,OpUserActivityCodeDao> {

    /**
     * 查询用户参加的活动的赠送优惠记录
     * @param userId 用户ID
     * @param activityId 活动ID
     * @return List<OpUserActivityCode>
     */
    public List<OpUserActivityCode> findUserActivityCodeList(BigDecimal userId,BigDecimal activityId){
        List<OpUserActivityCode> activityCodeList = this.find(" userId="+userId+" and activityId="+activityId,null,null);
        return activityCodeList;
    }

    /**
     * 判断用户参加的活动是否有赠送过优惠券
     * @param userId 用户ID
     * @param activityId　活动ID
     * @return true赠送过，false未赠送过
     */
    public boolean isUserActivityCode(BigDecimal userId,BigDecimal activityId){
        List<OpUserActivityCode> codeList = this.findUserActivityCodeList(userId,activityId);
        if(ObjectUtils.isNotEmpty(codeList)){
            return true;
        }
        return false;
    }
}
